package commons;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Runnable implements ActionListener {

	public static void main(String[] args) {

		new GUI(new Runnable());
	}
	
	/**add all function events here.... */
	@Override
	public void actionPerformed(ActionEvent event) {

		String text = GUI.display.getText();
		
		if (event.getActionCommand() == "\u0065 \u036F") {
            CalculatorHarsh cal = new CalculatorHarsh();
			if (text.equals("0")) {
				GUI.display.setText("1");
			} else if (text.isEmpty()) {
				GUI.display.setText("Math ERROR");
			} else {
				GUI.display.setText(cal.expFunc(GUI.display.getText()).toString());
			}
		}
		else if(event.getActionCommand() == "x \u036F"){
			CalculatorShewetaank cal = new CalculatorShewetaank();
			if(text.equals("0") || text.isEmpty()){
				GUI.display.setText("Math ERROR");
			} else {
				GUI.display.setText(cal.getUserValue(GUI.display.getText()).toString());
			}
		}
		else if (event.getActionCommand() == "tan") {

			CalculatorAshish cal = new CalculatorAshish();
			if (text.isEmpty()) {
				GUI.display.setText("Math ERROR");
			} else {
				GUI.display.setText(cal.tanFunc(GUI.display.getText()).toString());
			}
		}
		else if (event.getActionCommand() == "log") {
            
			if (text.isEmpty()) {
				GUI.display.setText("Math ERROR");
			} else {
				CalculatorSandeep Cal = new CalculatorSandeep(GUI.display.getText());
				double result =  Cal.calculate();
				GUI.display.setText(new Double(result).toString());
			}
		}
		else if(event.getActionCommand() == "cos"){
			CalculatorShruthi cal = new CalculatorShruthi();
			if (text.equals("0")) {
				GUI.display.setText("1");
			} else if (text.isEmpty()) {
				GUI.display.setText("Math ERROR");
			} else {
				GUI.display.setText(cal.calculateCos(GUI.display.getText()).toString());
			}
}
		else if (event.getActionCommand() == "10 \u036F") {
			CalculatorAshwin cal = new CalculatorAshwin();
			if (text.isEmpty()) {
				GUI.display.setText("Math ERROR");
			}
				if (text.equals("0")) {
					GUI.display.setText("1");
			} else {
				GUI.display.setText(cal.pow(GUI.display.getText()).toString());
			}
		}
		else if(event.getActionCommand() == "sin"){
			CalculatorMarzieh cal = new CalculatorMarzieh();
			if (text.isEmpty()) {
				GUI.display.setText("Math ERROR");
			}
				
				GUI.display.setText(cal.sinFunc(GUI.display.getText()).toString());
			
		}

	}
}
